/**
 * @author 蔡明宗
 * @date 2012-10-31 10:11:15
 */

package com.gossip.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gossip.data.jdbc.TipData;
import com.gossip.model.Common;
import com.gossip.model.Tip;
import com.gossip.model.TipDiv;

/**
 * @author Administrator
 * 
 */
public class AddTip extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5753531701442643054L;

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setCharacterEncoding("UTF-8");
		// PrintWriter out = resp.getWriter();
		String content = req.getParameter("cnt");
		String color = req.getParameter("clr");
		// System.out.println(Common.chineseDecode(content));

		if (!Common.isEmpty(content)) {
			Tip tip = new Tip();
			tip.setContent(Common.chineseDecode(content));
			tip.setBackground(color);
			tip.setDivStyle(new TipDiv().getTipStyle(tip));
			TipData.insertTip(tip);
		}
		resp.sendRedirect(Common.homeUrl);
	}

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

}
